home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- '''distutils.extension
-
- Provides the Extension class, used to describe C/C++ extension
- modules in setup scripts.'''
- __revision__ = '$Id: extension.py,v 1.19 2004/10/14 10:02:08 anthonybaxter Exp $'
- import os
- import string
- import sys
- from types import *
-
- try:
- import warnings
- except ImportError:
- warnings = None
-
-
- class Extension:
- '''Just a collection of attributes that describes an extension
- module and everything needed to build it (hopefully in a portable
- way, but there are hooks that let you be as unportable as you need).
-
- Instance attributes:
- name : string
- the full name of the extension, including any packages -- ie.
- *not* a filename or pathname, but Python dotted name
- sources : [string]
- list of source filenames, relative to the distribution root
- (where the setup script lives), in Unix form (slash-separated)
- for portability. Source files may be C, C++, SWIG (.i),
- platform-specific resource files, or whatever else is recognized
- by the "build_ext" command as source for a Python extension.
- include_dirs : [string]
- list of directories to search for C/C++ header files (in Unix
- form for portability)
- define_macros : [(name : string, value : string|None)]
- list of macros to define; each macro is defined using a 2-tuple,
- where \'value\' is either the string to define it to or None to
- define it without a particular value (equivalent of "#define
- FOO" in source or -DFOO on Unix C compiler command line)
- undef_macros : [string]
- list of macros to undefine explicitly
- library_dirs : [string]
- list of directories to search for C/C++ libraries at link time
- libraries : [string]
- list of library names (not filenames or paths) to link against
- runtime_library_dirs : [string]
- list of directories to search for C/C++ libraries at run time
- (for shared extensions, this is when the extension is loaded)
- extra_objects : [string]
- list of extra files to link with (eg. object files not implied
- by \'sources\', static library that must be explicitly specified,
- binary resource files, etc.)
- extra_compile_args : [string]
- any extra platform- and compiler-specific information to use
- when compiling the source files in \'sources\'. For platforms and
- compilers where "command line" makes sense, this is typically a
- list of command-line arguments, but for other platforms it could
- be anything.
- extra_link_args : [string]
- any extra platform- and compiler-specific information to use
- when linking object files together to create the extension (or
- to create a new static Python interpreter). Similar
- interpretation as for \'extra_compile_args\'.
- export_symbols : [string]
- list of symbols to be exported from a shared extension. Not
- used on all platforms, and not generally necessary for Python
- extensions, which typically export exactly one symbol: "init" +
- extension_name.
- swig_opts : [string]
- any extra options to pass to SWIG if a source file has the .i
- extension.
- depends : [string]
- list of files that the extension depends on
- language : string
- extension language (i.e. "c", "c++", "objc"). Will be detected
- from the source extensions if not provided.
- '''
-
- def __init__(self, name, sources, include_dirs = None, define_macros = None, undef_macros = None, library_dirs = None, libraries = None, runtime_library_dirs = None, extra_objects = None, extra_compile_args = None, extra_link_args = None, export_symbols = None, swig_opts = None, depends = None, language = None, **kw):
- if not type(name) is StringType:
- raise AssertionError, "'name' must be a string"
- if not type(sources) is ListType or map(type, sources) == [
- StringType] * len(sources):
- raise AssertionError, "'sources' must be a list of strings"
- self.name = name
- self.sources = sources
- if not include_dirs:
- pass
- self.include_dirs = []
- if not define_macros:
- pass
- self.define_macros = []
- if not undef_macros:
- pass
- self.undef_macros = []
- if not library_dirs:
- pass
- self.library_dirs = []
- if not libraries:
- pass
- self.libraries = []
- if not runtime_library_dirs:
- pass
- self.runtime_library_dirs = []
- if not extra_objects:
- pass
- self.extra_objects = []
- if not extra_compile_args:
- pass
- self.extra_compile_args = []
- if not extra_link_args:
- pass
- self.extra_link_args = []
- if not export_symbols:
- pass
- self.export_symbols = []
- if not swig_opts:
- pass
- self.swig_opts = []
- if not depends:
- pass
- self.depends = []
- self.language = language
- if len(kw):
- L = kw.keys()
- L.sort()
- L = map(repr, L)
- msg = 'Unknown Extension options: ' + string.join(L, ', ')
- if warnings is not None:
- warnings.warn(msg)
- else:
- sys.stderr.write(msg + '\n')
-
-
-
-
- def read_setup_file(filename):
- parse_makefile = parse_makefile
- expand_makefile_vars = expand_makefile_vars
- _variable_rx = _variable_rx
- import distutils.sysconfig
- TextFile = TextFile
- import distutils.text_file
- split_quoted = split_quoted
- import distutils.util
- vars = parse_makefile(filename)
- file = TextFile(filename, strip_comments = 1, skip_blanks = 1, join_lines = 1, lstrip_ws = 1, rstrip_ws = 1)
- extensions = []
- while None:
- line = file.readline()
- if line is None:
- break
-
- if _variable_rx.match(line):
- continue
-
- if line[-1] == line[-1]:
- pass
- elif line[-1] == '*':
- file.warn("'%s' lines not handled yet" % line)
- continue
-
- line = expand_makefile_vars(line, vars)
- words = split_quoted(line)
- module = words[0]
- ext = Extension(module, [])
- append_next_word = None
- for word in words[1:]:
- if append_next_word is not None:
- append_next_word.append(word)
- append_next_word = None
- continue
-
- suffix = os.path.splitext(word)[1]
- switch = word[0:2]
- value = word[2:]
- if suffix in ('.c', '.cc', '.cpp', '.cxx', '.c++', '.m', '.mm'):
- ext.sources.append(word)
- continue
- if switch == '-I':
- ext.include_dirs.append(value)
- continue
- if switch == '-D':
- equals = string.find(value, '=')
- if equals == -1:
- ext.define_macros.append((value, None))
- else:
- ext.define_macros.append((value[0:equals], value[equals + 2:]))
- equals == -1
- if switch == '-U':
- ext.undef_macros.append(value)
- continue
- if switch == '-C':
- ext.extra_compile_args.append(word)
- continue
- if switch == '-l':
- ext.libraries.append(value)
- continue
- if switch == '-L':
- ext.library_dirs.append(value)
- continue
- if switch == '-R':
- ext.runtime_library_dirs.append(value)
- continue
- if word == '-rpath':
- append_next_word = ext.runtime_library_dirs
- continue
- if word == '-Xlinker':
- append_next_word = ext.extra_link_args
- continue
- if word == '-Xcompiler':
- append_next_word = ext.extra_compile_args
- continue
- if switch == '-u':
- ext.extra_link_args.append(word)
- if not value:
- append_next_word = ext.extra_link_args
-
- value
- if suffix in ('.a', '.so', '.sl', '.o', '.dylib'):
- ext.extra_objects.append(word)
- continue
- file.warn("unrecognized argument '%s'" % word)
-
- return extensions
-
-